package club.kingyin.kyblogprocore.service.impl;

import club.kingyin.commons.entity.core.Comment;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import club.kingyin.kyblogprocore.dao.CommentDao;
import club.kingyin.kyblogprocore.service.CommentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * (Comment)表服务实现类
 *
 * @author makejava
 * @since 2022-02-16 18:20:33
 */
@Service("commentService")
public class CommentServiceImpl extends ServiceImpl<CommentDao, Comment> implements CommentService {

    @Resource
    private CommentDao commentDao;

    public Page<Comment> selectComments(Page<Comment> page, Comment comment) {
        LambdaQueryWrapper<Comment> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(Comment::getObjectid, comment.getObjectid());
        if (comment.getParentid() != null)
            queryWrapper.eq(Comment::getParentid, comment.getParentid());
        else queryWrapper.isNull(Comment::getParentid);
        return commentDao.selectPage(page, queryWrapper);
    }

}

